<template>

  <body class="bacstyle">
    <!-- 登录盒子 -->
    <div class="loginBox">
      <!-- logo -->
      <h2 class="logo">家族族谱管理系统</h2>
      <!-- 登录盒子 -->
      <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" label-width="0px" class="login_form">
        <!-- 登录账号 -->
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <!-- 登录密码 -->
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" prefix-icon="el-icon-lock" type="password"></el-input>
        </el-form-item>
        <!-- 登录按钮 -->
        <el-form-item class="btns">
          <el-button type="primary" @click="login" round>登录</el-button>
          <el-button type="info" @click="resetLoginForm" round>重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </body>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginFormRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields()
    },
    login() {
      this.$refs.loginFormRef.validate(valid => {
        if (!valid) return
        // const result = this.$http.post('login', this.loginForm)
        // console.log(result)
        if (this.loginForm.username === 'admin' && this.loginForm.password === '123456') {
          this.$message.success('登陆成功！')
          return this.$router.push('/home')
        } else {
          return this.$message.error('用户名或密码错误！')
        }
      })
    }
  }
}

</script>

<style lang="less" scoped>
.bacstyle {
  background-color: #43576a;
  height: 100%;
}

.loginBox {
  background-color: #BDC3C7;
  height: 300px;
  width: 430px;
  border-radius: 25px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.btns {
  display: flex;
  justify-content: flex-end;
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 30px;
  box-sizing: border-box;
}

.logo {
  color: #090a0a;
  border-radius: 5px;
  position: absolute;
  left: 50%;
  top: 10%;
  transform: translate(-50%, -50%);
  padding: 10px 10px 10px;
  box-sizing: border-box;
}
</style>
